/**
 * 
 */
package za.co.sindi.oauth.server.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Buhake Sindi
 * @since 26 March 2012
 *
 */
public class ServiceConfig implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5154397646350850921L;
	private String name;
	private String className;
	private String path;
	private boolean annotated;
	private boolean serviceSubclass;
	private List<RequestConfig> requestConfigList;
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}

	/**
	 * @param className the className to set
	 */
	public void setClassName(String className) {
		this.className = className;
	}

	/**
	 * @return the path
	 */
	public String getPath() {
		return path;
	}
	
	/**
	 * @param path the path to set
	 */
	public void setPath(String path) {
		this.path = path;
	}
	
	/**
	 * @return the annotated
	 */
	public boolean isAnnotated() {
		return annotated;
	}
	
	/**
	 * @param annotated the annotated to set
	 */
	public void setAnnotated(boolean annotated) {
		this.annotated = annotated;
	}
	
	/**
	 * @return the serviceSubclass
	 */
	public boolean isServiceSubclass() {
		return serviceSubclass;
	}

	/**
	 * @param serviceSubclass the serviceSubclass to set
	 */
	public void setServiceSubclass(boolean serviceSubclass) {
		this.serviceSubclass = serviceSubclass;
	}

	/**
	 * Add a {@link RequestConfig} to the Request Config list.
	 * @param requestConfig
	 */
	public void addRequestConfig(RequestConfig requestConfig) {
		if (requestConfigList == null) {
			requestConfigList = new ArrayList<RequestConfig>();
		}
		
		if (requestConfig != null) {
			for (RequestConfig request : getRequestConfigs()) {
				if (request.getMethod().equals(requestConfig.getMethod())) {
					throw new IllegalArgumentException("Duplicate request with method '" + requestConfig.getMethod() + "'.");
				}
			}
			
			requestConfigList.add(requestConfig);
		}
	}

	/**
	 * @return the requestConfigList
	 */
	public RequestConfig[] getRequestConfigs() {
		if (requestConfigList == null) {
			return null;
		}
		
		return requestConfigList.toArray(new RequestConfig[requestConfigList.size()]);
	}
}
